package com.project.service.PurchaseOrderService.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.project.bean.PurchaseOrderBean;
import com.project.bean.ShopCarBean;
import com.project.mapper.IPurchaseMapper.IPurchaseOrderMapper;
import com.project.service.PurchaseOrderService.IPurchaseOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.util.Map;

@Service
@Transactional
public class PurchaseOrderServiceImpl implements IPurchaseOrderService {
    @Autowired
    private IPurchaseOrderMapper mapper;

    @Override
    public void addOrder(PurchaseOrderBean order, Map<Integer, ShopCarBean> shopMap) {
        mapper.addPurchaseOrder(order);
        mapper.addPurchaseInfo(order.getId(), shopMap.values());
    }

    @Override
    public PurchaseOrderBean findById(int orderId) {
        return mapper.findById(orderId);
    }

    @Override
    public PageInfo<PurchaseOrderBean> findByItem(int pageNO, String name, LocalDate startDate, LocalDate endDate) {
        PageHelper.startPage(pageNO,PAGESIZE);
        PageInfo<PurchaseOrderBean> pageInfo = PageInfo.of(mapper.findByItem(name, startDate, endDate));
        return pageInfo;
    }
}
